<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>电话薄</title>
<script language="JavaScript" type="text/JavaScript">
var fPath=null;
var name;
var py;
var tel;
var remark;		 	 
var nameArr;
var pyArr;
var telArr;
var remarkArr;
var doc;
function setPath(){
	fPath = document.getElementById("fPath").value;
}

function loadXMLFile(){
    doc = new ActiveXObject("Msxml2.DOMDocument");
    doc.async = false;
	doc.load(fPath);
	//alert(doc.url);
}

function getPageData(){
 name = document.getElementById("name");
 py = document.getElementById("py");
 tel = document.getElementById("tel");
 remark = document.getElementById("remark");
}

function getXMLData(){		 	 
	 nameArr =  doc.getElementsByTagName("name");
	 pyArr = doc.getElementsByTagName("py");
	 telArr = doc.getElementsByTagName("tel");
	 remarkArr = doc.getElementsByTagName("remark");
}

function find(){
	loadXMLFile();
	getXMLData();
	getPageData(); 
	for(var i=0;i<nameArr.length;i++){		
		if(name.value == nameArr[i].text){
			document.getElementById("result").innerHTML = "<b>查询结果:</b><br/>姓名："+nameArr[i].text+"<br/>电话："+telArr[i].text+"<br/>备注："+remarkArr[i].text;
		}
	}
	
}

function save(){
loadXMLFile();
getPageData(); 
//if(name.value == "" || py.value=="" || tel.value=="" || remark.value=="")
	//alert("信息不能为空");	
doc.save();
}
function validator(obj){
				try {
					var span = document.createElement("SPAN");
					span.id = "_ErrorMessagePanel";
					span.style.color = "red";
					obj.parentNode.appendChild(span);
					span.innerHTML = "请正确输入该信息";
				}
				catch (e) {
					alert(e.description);
				}
}
</script>
</head>

<body>
请选择您要查询的XML文件：<br/>
<input type='file' id="fPath" onchange="setPath()"/><br/><br/>
<label>姓名：
<input name="name" type="text" id="name" onkeydown="find()" ondblclick="validator(this)"/>
</label>
<br />
<br />
简拼：
<input name="py" type="text" id="py" />
<br />
<br />
电话：
<input name="tel" type="text" id="tel" />
<br />
<br />
备注：
<textarea name="remark" id="remark"></textarea>
<br />
 <input type="submit" name="Submit" value="查询" onClick="find()" />
 <input type="submit" name="Submit2" value="保存" disabled="disabled"/>
 <p>
 <div id="result"></div>
 </p>
</body>
</html>
